<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2012 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */

class base_facades_route extends base_facades_facade
{
    /**
	 * The router instance
	 *
	 * @var base_routing_router
	 */
    private static $__router;

    /**
     * {@inheritDoc}
     */
    protected static function getFacadeAccessor()
    {
        if (!static::$__router)
        {
            static::$__router = kernel::single('base_routing_router');
            static::loadRoutes();
        }
        return static::$__router;
    }

	/**
	 * Load the application routes.
	 *
	 * @return void
	 */
	protected static function loadRoutes()
	{
        $path = BOOT_DIR.'/routes.php';

        $file = kernel::single('base_filesystem');

        if ($file->exists($path)) {
            return require($path);
        }

        throw new ErrorException('Cannot load routes.');
	}
}
